package cn.com.taiji.core;

import java.util.List;

import com.jfinal.plugin.activerecord.generator.TableMeta;

import cn.hutool.core.util.StrUtil;

/**
 * @author dongwei dongweia@mail.taiji.com.cn
 */
public class CommonRun {
    static List<TableMeta> tableMetaListCache = null;

    private static List<TableMeta> getTableMetaListCache(String[] tableNames, String prefix) {
        if (null == tableMetaListCache) {
            tableMetaListCache = CodeGenHelpler.createMetaBuilder(tableNames, prefix).build();
        }
        return tableMetaListCache;
    }

    public static void doGenerate(String[] tableNames, String suffix, CommonGenTemplate template) {
        String type = null;
        if (StrUtil.isNotBlank(suffix) && "jsp".equals(suffix)) {
            type = suffix;
            suffix = "";
        }
        template.generate(getTableMetaListCache(tableNames, suffix));
        if (null != type && type.equals("jsp")) {
            suffix = type;
        }
        System.out.println((StrUtil.isBlank(suffix) ? "entity" : suffix) + "  生成 !!!");
    }

    public static void doGenerate(String[] tableNames, String suffix, String mpackage, CommonGenTemplate template) {
        String type = null;
        if (StrUtil.isNotBlank(suffix) && "jsp".equals(suffix)) {
            type = suffix;
            suffix = "";
        }
        template.generate(getTableMetaListCache(tableNames, suffix),mpackage);
        if (null != type && type.equals("jsp")) {
            suffix = type;
        }
        System.out.println((StrUtil.isBlank(suffix) ? "entity" : suffix) + "  生成 !!!");
    }
}
